class MyRange:
    def __init__(self, data):
        self.data = data

    def __iter__(self):
        return MyRangeIterator(self.data)


class MyRangeIterator:
    def __init__(self, num):
        self.num = num
        self.index = -1

    def __next__(self):
        if self.index == self.num - 1:
            raise StopIteration()
        self.index += 1
        return self.index


obj = MyRange(5)
iterator = obj.__iter__()
while True:
    try:
        item = iterator.__next__()
        print(item)
    except StopIteration:
        break

# yield


